def deldups(items, key = None):
     '''删除列表的重复元素并保存顺序不变'''
     seen = set()
     for item in items:
          value = item if key is None else key(item)
          if value not in seen:
               yield item
               seen.add(value)

if __name__ == '__main__':
     a = [4, 4, 3, 3, 5, 6, 7]
     print(a)
     print(list(deldups(a)))
     
     b = [{'x' : 1, 'y' : 2}, {'x' : 1, 'y' : 2}, {'x' : 1, 'y' : 2}]
     print(list(deldups(b, key = lambda item: (item['x'], item['y']))))
